/**
 * panel to display itemss
 */
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class ItemPanel extends JPanel{
        
        /**
         * Field LIU.
         * (value is 6)
         */
        private static final int LIU = 6;
        
		/**
		 * Field WUBAI.
		 * (value is 500)
		 */
		private static final int WUBAI = 500;
		
		/**
		 * Field ER.
		 * (value is 2)
		 */
		private static final int ER = 2;
		
		/**
		 * Field BABAI.
		 * (value is 800)
		 */
		private static final int BABAI = 800;
		
		/**
         * Field templeKey.
         */
        public static JLabel TempleKey=null;
        
        /**
         * Constructor for ItemPanel.
         */
        public ItemPanel() {
                setSize(BABAI, WUBAI);
                setLayout(new GridLayout(LIU, ER));
                add(new JLabel("Temple Key"));
                add(new JLabel(""));
                add(new JLabel("You own: "));
                setTempleKey(new JLabel("" + PlayerInfo.TempleKey));
                add(getTempleKey());
                add(new JLabel("Price: "));
                add(new JLabel("2000"));
                final JButton buy=new JButton("Buy");
                buy.addActionListener(new TempleKeyListener());
                add(buy);
                add(new JLabel(""));
                add(new JLabel(""));
                final Button exitButton=new Button("Exit");
                exitButton.addActionListener(new ExitItemListener());
                add(exitButton);
        }
        
        /**
         * Method getTempleKey.
        
         * @return JLabel */
        public static JLabel getTempleKey() {
			return TempleKey;
		}

		/**
		 * Method setTempleKey.
		 * @param templeKey JLabel
		 */
		public static void setTempleKey(JLabel templeKey) {
			ItemPanel.TempleKey = templeKey;
		}

		/**
		 * @author Master
		 */
		public static class TempleKeyListener implements ActionListener{
			
		/**
		 * Field LIANGQIAN.
		 * (value is 2000)
		 */
		private static final int LIANGQIAN = 2000;

		/**
		 * Method toString.
		
		 * @return String */
		@Override
		public String toString() {
			return "templeKeyListener []";
		}

		/**
		 * Method actionPerformed.
		 * @param e ActionEvent
		
		 * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */
		@Override
		public void actionPerformed(ActionEvent e) {
			if (PlayerInfo.Money >= LIANGQIAN){
				PlayerInfo.TempleKey++;
				getTempleKey().setText("" + PlayerInfo.TempleKey);
				PlayerInfo.Money-=LIANGQIAN;
				MarketPlaceScreen.Money.setText("" + PlayerInfo.Money);
			}
			else {
				JOptionPane.showMessageDialog(
					ConfigurationScreen.MyFrame, "not enough money");
			}
		}
		
	}
}
